<?php
$loader->requireOnce('includes/ServiceDiscount/TicketItemPayment.class.php');

class TestItemPayment extends TicketItemPayment {
	
	function __construct($discountBehaviour) {
		parent::__construct($discountBehaviour);
	}
	
	/**
	 * Calculate prices for action "update price of a ticket item"
	 *
	 * @param int $ticketItemId
	 * @param String $insuranceType
	 */
	public function add($ticketItemId, $insuranceType) {
		$test = Celini::newORDO('TestItemAssoService');
		$res = $test->getServiceInATest($ticketItemId);

		$result = array('original_price' => 0,
						'patient_price' => 0,
						'insurance_price' => 0,
						'discount' => 0);
		foreach ($res as $item) {			
			$temp = $this->getServicePrice($item['service_id'], $insuranceType);
			// Only discount of sale program
			$discountAmount = $this->discountBehaviour->discountOnSaleProgram($item['service_id'], $temp['patient_price']);
			$result['original_price'] += $temp['original_price'];
			$result['patient_price'] += $temp['patient_price'];
			$result['insurance_price'] += $temp['insurance_price'];
			$result['discount'] += $discountAmount;
			
			$temp['discount'] = $discountAmount;
			
			$test->updateItemPrice($ticketItemId, $item['service_id'], $temp);		
			
		}
		$this->result = $result;		
	}
	
	public function update($ticketItemId) {
		// do nothing
	}
}
?>